package com.sjgs.gis;

import org.springframework.beans.BeansException;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.stereotype.Component;

@SpringBootApplication
@EnableDiscoveryClient
public class GeoserverDcApplication implements ApplicationContextAware {
    private static ApplicationContext applicationContext = null;

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(GeoserverDcApplication.class);
        ConfigurableApplicationContext context = app.run(args);
        ConfigurableEnvironment env = context.getEnvironment();
        GeoserverDcApplication App = applicationContext.getBean(GeoserverDcApplication.class);
        context.setEnvironment(App.setEnv(env));
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public ConfigurableEnvironment setEnv(ConfigurableEnvironment env) {
        return env;
    }

    @Component
    @Order(1)
    class Runner1 implements CommandLineRunner {
        @Override
        public void run(String... args) throws Exception {
            System.out.println("Step 3: The Runner1 run ...");
        }
    }
}
